// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Requests;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Snapshot;

public sealed partial class RestoreRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>
	/// Explicit operation timeout for connection to master node
	/// </para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("master_timeout"); set => Q("master_timeout", value); }

	/// <summary>
	/// <para>
	/// Should this request wait until the operation has completed before returning
	/// </para>
	/// </summary>
	public bool? WaitForCompletion { get => Q<bool?>("wait_for_completion"); set => Q("wait_for_completion", value); }
}

/// <summary>
/// <para>
/// Restores a snapshot.
/// </para>
/// </summary>
public sealed partial class RestoreRequest : PlainRequest<RestoreRequestParameters>
{
	public RestoreRequest(Elastic.Clients.Elasticsearch.Serverless.Name repository, Elastic.Clients.Elasticsearch.Serverless.Name snapshot) : base(r => r.Required("repository", repository).Required("snapshot", snapshot))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SnapshotRestore;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "snapshot.restore";

	/// <summary>
	/// <para>
	/// Explicit operation timeout for connection to master node
	/// </para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? MasterTimeout { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("master_timeout"); set => Q("master_timeout", value); }

	/// <summary>
	/// <para>
	/// Should this request wait until the operation has completed before returning
	/// </para>
	/// </summary>
	[JsonIgnore]
	public bool? WaitForCompletion { get => Q<bool?>("wait_for_completion"); set => Q("wait_for_completion", value); }
	[JsonInclude, JsonPropertyName("feature_states")]
	public ICollection<string>? FeatureStates { get; set; }
	[JsonInclude, JsonPropertyName("ignore_index_settings")]
	public ICollection<string>? IgnoreIndexSettings { get; set; }
	[JsonInclude, JsonPropertyName("ignore_unavailable")]
	public bool? IgnoreUnavailable { get; set; }
	[JsonInclude, JsonPropertyName("include_aliases")]
	public bool? IncludeAliases { get; set; }
	[JsonInclude, JsonPropertyName("include_global_state")]
	public bool? IncludeGlobalState { get; set; }
	[JsonInclude, JsonPropertyName("index_settings")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettings? IndexSettings { get; set; }
	[JsonInclude, JsonPropertyName("indices")]
	public Elastic.Clients.Elasticsearch.Serverless.Indices? Indices { get; set; }
	[JsonInclude, JsonPropertyName("partial")]
	public bool? Partial { get; set; }
	[JsonInclude, JsonPropertyName("rename_pattern")]
	public string? RenamePattern { get; set; }
	[JsonInclude, JsonPropertyName("rename_replacement")]
	public string? RenameReplacement { get; set; }
}

/// <summary>
/// <para>
/// Restores a snapshot.
/// </para>
/// </summary>
public sealed partial class RestoreRequestDescriptor<TDocument> : RequestDescriptor<RestoreRequestDescriptor<TDocument>, RestoreRequestParameters>
{
	internal RestoreRequestDescriptor(Action<RestoreRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public RestoreRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Name repository, Elastic.Clients.Elasticsearch.Serverless.Name snapshot) : base(r => r.Required("repository", repository).Required("snapshot", snapshot))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SnapshotRestore;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "snapshot.restore";

	public RestoreRequestDescriptor<TDocument> MasterTimeout(Elastic.Clients.Elasticsearch.Serverless.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
	public RestoreRequestDescriptor<TDocument> WaitForCompletion(bool? waitForCompletion = true) => Qs("wait_for_completion", waitForCompletion);

	public RestoreRequestDescriptor<TDocument> Repository(Elastic.Clients.Elasticsearch.Serverless.Name repository)
	{
		RouteValues.Required("repository", repository);
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> Snapshot(Elastic.Clients.Elasticsearch.Serverless.Name snapshot)
	{
		RouteValues.Required("snapshot", snapshot);
		return Self;
	}

	private ICollection<string>? FeatureStatesValue { get; set; }
	private ICollection<string>? IgnoreIndexSettingsValue { get; set; }
	private bool? IgnoreUnavailableValue { get; set; }
	private bool? IncludeAliasesValue { get; set; }
	private bool? IncludeGlobalStateValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettings? IndexSettingsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor<TDocument> IndexSettingsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor<TDocument>> IndexSettingsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices? IndicesValue { get; set; }
	private bool? PartialValue { get; set; }
	private string? RenamePatternValue { get; set; }
	private string? RenameReplacementValue { get; set; }

	public RestoreRequestDescriptor<TDocument> FeatureStates(ICollection<string>? featureStates)
	{
		FeatureStatesValue = featureStates;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IgnoreIndexSettings(ICollection<string>? ignoreIndexSettings)
	{
		IgnoreIndexSettingsValue = ignoreIndexSettings;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IgnoreUnavailable(bool? ignoreUnavailable = true)
	{
		IgnoreUnavailableValue = ignoreUnavailable;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IncludeAliases(bool? includeAliases = true)
	{
		IncludeAliasesValue = includeAliases;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IncludeGlobalState(bool? includeGlobalState = true)
	{
		IncludeGlobalStateValue = includeGlobalState;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IndexSettings(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettings? indexSettings)
	{
		IndexSettingsDescriptor = null;
		IndexSettingsDescriptorAction = null;
		IndexSettingsValue = indexSettings;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IndexSettings(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor<TDocument> descriptor)
	{
		IndexSettingsValue = null;
		IndexSettingsDescriptorAction = null;
		IndexSettingsDescriptor = descriptor;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> IndexSettings(Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor<TDocument>> configure)
	{
		IndexSettingsValue = null;
		IndexSettingsDescriptor = null;
		IndexSettingsDescriptorAction = configure;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Serverless.Indices? indices)
	{
		IndicesValue = indices;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> Partial(bool? partial = true)
	{
		PartialValue = partial;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> RenamePattern(string? renamePattern)
	{
		RenamePatternValue = renamePattern;
		return Self;
	}

	public RestoreRequestDescriptor<TDocument> RenameReplacement(string? renameReplacement)
	{
		RenameReplacementValue = renameReplacement;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FeatureStatesValue is not null)
		{
			writer.WritePropertyName("feature_states");
			JsonSerializer.Serialize(writer, FeatureStatesValue, options);
		}

		if (IgnoreIndexSettingsValue is not null)
		{
			writer.WritePropertyName("ignore_index_settings");
			JsonSerializer.Serialize(writer, IgnoreIndexSettingsValue, options);
		}

		if (IgnoreUnavailableValue.HasValue)
		{
			writer.WritePropertyName("ignore_unavailable");
			writer.WriteBooleanValue(IgnoreUnavailableValue.Value);
		}

		if (IncludeAliasesValue.HasValue)
		{
			writer.WritePropertyName("include_aliases");
			writer.WriteBooleanValue(IncludeAliasesValue.Value);
		}

		if (IncludeGlobalStateValue.HasValue)
		{
			writer.WritePropertyName("include_global_state");
			writer.WriteBooleanValue(IncludeGlobalStateValue.Value);
		}

		if (IndexSettingsDescriptor is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, IndexSettingsDescriptor, options);
		}
		else if (IndexSettingsDescriptorAction is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor<TDocument>(IndexSettingsDescriptorAction), options);
		}
		else if (IndexSettingsValue is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, IndexSettingsValue, options);
		}

		if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (PartialValue.HasValue)
		{
			writer.WritePropertyName("partial");
			writer.WriteBooleanValue(PartialValue.Value);
		}

		if (!string.IsNullOrEmpty(RenamePatternValue))
		{
			writer.WritePropertyName("rename_pattern");
			writer.WriteStringValue(RenamePatternValue);
		}

		if (!string.IsNullOrEmpty(RenameReplacementValue))
		{
			writer.WritePropertyName("rename_replacement");
			writer.WriteStringValue(RenameReplacementValue);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>
/// Restores a snapshot.
/// </para>
/// </summary>
public sealed partial class RestoreRequestDescriptor : RequestDescriptor<RestoreRequestDescriptor, RestoreRequestParameters>
{
	internal RestoreRequestDescriptor(Action<RestoreRequestDescriptor> configure) => configure.Invoke(this);

	public RestoreRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Name repository, Elastic.Clients.Elasticsearch.Serverless.Name snapshot) : base(r => r.Required("repository", repository).Required("snapshot", snapshot))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SnapshotRestore;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "snapshot.restore";

	public RestoreRequestDescriptor MasterTimeout(Elastic.Clients.Elasticsearch.Serverless.Duration? masterTimeout) => Qs("master_timeout", masterTimeout);
	public RestoreRequestDescriptor WaitForCompletion(bool? waitForCompletion = true) => Qs("wait_for_completion", waitForCompletion);

	public RestoreRequestDescriptor Repository(Elastic.Clients.Elasticsearch.Serverless.Name repository)
	{
		RouteValues.Required("repository", repository);
		return Self;
	}

	public RestoreRequestDescriptor Snapshot(Elastic.Clients.Elasticsearch.Serverless.Name snapshot)
	{
		RouteValues.Required("snapshot", snapshot);
		return Self;
	}

	private ICollection<string>? FeatureStatesValue { get; set; }
	private ICollection<string>? IgnoreIndexSettingsValue { get; set; }
	private bool? IgnoreUnavailableValue { get; set; }
	private bool? IncludeAliasesValue { get; set; }
	private bool? IncludeGlobalStateValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettings? IndexSettingsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor IndexSettingsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor> IndexSettingsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices? IndicesValue { get; set; }
	private bool? PartialValue { get; set; }
	private string? RenamePatternValue { get; set; }
	private string? RenameReplacementValue { get; set; }

	public RestoreRequestDescriptor FeatureStates(ICollection<string>? featureStates)
	{
		FeatureStatesValue = featureStates;
		return Self;
	}

	public RestoreRequestDescriptor IgnoreIndexSettings(ICollection<string>? ignoreIndexSettings)
	{
		IgnoreIndexSettingsValue = ignoreIndexSettings;
		return Self;
	}

	public RestoreRequestDescriptor IgnoreUnavailable(bool? ignoreUnavailable = true)
	{
		IgnoreUnavailableValue = ignoreUnavailable;
		return Self;
	}

	public RestoreRequestDescriptor IncludeAliases(bool? includeAliases = true)
	{
		IncludeAliasesValue = includeAliases;
		return Self;
	}

	public RestoreRequestDescriptor IncludeGlobalState(bool? includeGlobalState = true)
	{
		IncludeGlobalStateValue = includeGlobalState;
		return Self;
	}

	public RestoreRequestDescriptor IndexSettings(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettings? indexSettings)
	{
		IndexSettingsDescriptor = null;
		IndexSettingsDescriptorAction = null;
		IndexSettingsValue = indexSettings;
		return Self;
	}

	public RestoreRequestDescriptor IndexSettings(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor descriptor)
	{
		IndexSettingsValue = null;
		IndexSettingsDescriptorAction = null;
		IndexSettingsDescriptor = descriptor;
		return Self;
	}

	public RestoreRequestDescriptor IndexSettings(Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor> configure)
	{
		IndexSettingsValue = null;
		IndexSettingsDescriptor = null;
		IndexSettingsDescriptorAction = configure;
		return Self;
	}

	public RestoreRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Serverless.Indices? indices)
	{
		IndicesValue = indices;
		return Self;
	}

	public RestoreRequestDescriptor Partial(bool? partial = true)
	{
		PartialValue = partial;
		return Self;
	}

	public RestoreRequestDescriptor RenamePattern(string? renamePattern)
	{
		RenamePatternValue = renamePattern;
		return Self;
	}

	public RestoreRequestDescriptor RenameReplacement(string? renameReplacement)
	{
		RenameReplacementValue = renameReplacement;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FeatureStatesValue is not null)
		{
			writer.WritePropertyName("feature_states");
			JsonSerializer.Serialize(writer, FeatureStatesValue, options);
		}

		if (IgnoreIndexSettingsValue is not null)
		{
			writer.WritePropertyName("ignore_index_settings");
			JsonSerializer.Serialize(writer, IgnoreIndexSettingsValue, options);
		}

		if (IgnoreUnavailableValue.HasValue)
		{
			writer.WritePropertyName("ignore_unavailable");
			writer.WriteBooleanValue(IgnoreUnavailableValue.Value);
		}

		if (IncludeAliasesValue.HasValue)
		{
			writer.WritePropertyName("include_aliases");
			writer.WriteBooleanValue(IncludeAliasesValue.Value);
		}

		if (IncludeGlobalStateValue.HasValue)
		{
			writer.WritePropertyName("include_global_state");
			writer.WriteBooleanValue(IncludeGlobalStateValue.Value);
		}

		if (IndexSettingsDescriptor is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, IndexSettingsDescriptor, options);
		}
		else if (IndexSettingsDescriptorAction is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.IndexSettingsDescriptor(IndexSettingsDescriptorAction), options);
		}
		else if (IndexSettingsValue is not null)
		{
			writer.WritePropertyName("index_settings");
			JsonSerializer.Serialize(writer, IndexSettingsValue, options);
		}

		if (IndicesValue is not null)
		{
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
		}

		if (PartialValue.HasValue)
		{
			writer.WritePropertyName("partial");
			writer.WriteBooleanValue(PartialValue.Value);
		}

		if (!string.IsNullOrEmpty(RenamePatternValue))
		{
			writer.WritePropertyName("rename_pattern");
			writer.WriteStringValue(RenamePatternValue);
		}

		if (!string.IsNullOrEmpty(RenameReplacementValue))
		{
			writer.WritePropertyName("rename_replacement");
			writer.WriteStringValue(RenameReplacementValue);
		}

		writer.WriteEndObject();
	}
}